<#assign pageName="接收消息管理">
<@override name="head-styles">
</@override>
<@override name="page-content">
<form class="layui-form form-horizontal" role="form" method="post">
    <div class="layui-form-search panel">
        <input type="text" hidden="hidden" name="_STATE"/>
        <@ctrl.SingleSelectQuery path="bsMessageLog.type" labelText="消息类别" options=messageTypeMap![] text=1 value=0>
            <option value="">—全部—</option>
        </@ctrl.SingleSelectQuery>
        <@ctrl.SingleSelectQuery path="bsMessageLog.status" labelText="消息状态" options={"":"全部","0":"未阅","1":"已阅"} text=1 value=0 />
        <div class="margin-5">
            <a href="javascript:" onclick="$('form:first').submit();" class="layui-btn layui-btn-sm">
                <i class="layui-icon layui-icon-search"></i>查询
            </a>
            <a href="javascript:" class="layui-btn layui-btn-warm layui-btn-sm js-reset">
                <i class="layui-icon layui-icon-refresh-1"></i>重置
            </a>
            <a href="javascript:" class="layui-btn layui-btn-danger layui-btn-sm js-delete">
                <i class="layui-icon layui-icon-delete"></i>批量删除
            </a>
            <#if bsMessageLog.status != '1'>
            <a href="javascript:" class="layui-btn layui-btn-warm layui-btn-sm js-read">
                <i class="layui-icon layui-icon-edit"></i>批量已阅
            </a>
            </#if>
        </div>
    </div>
    <table class="layui-table">
       <thead>
           <tr>
               <th class="align-center" width="50">
                   <input type="checkbox" class="fullCheck" lay-skin="primary" lay-filter="fullCheck"/>
               </th>
               <th class="align-center">标题</th>
               <th class="align-center" width="200">类别</th>
               <th class="align-center" width="200">状态</th>
               <th class="align-center" width="200">时间</th>
           </tr>
       </thead>
       <tbody>
           <#if queryResult.rows?has_content>
               <#list queryResult.rows as dataItem>  
                   <tr>
                       <td class="align-center" width="50">
                           <input type="checkbox" class="messageItem"  lay-skin="primary" lay-filter="itemCheck" value="${dataItem.id}"/>
                       </td>
                       <td class="">
                           <a href="detail/${dataItem.id}">${dataItem.title}</a>
                       </td>
                       <td class="align-center" width="200">
                           <#if dataItem.type == "0">
                               <span class="">私信</span>
                           <#elseif dataItem.type == "1">
                               <span class="">公共消息</span>
                           <#elseif dataItem.type == "2">
                               <span class="">系统消息</span>
                           </#if>
                       </td>
                       <td class="align-center" nowrap="nowrap">
                            ${getStatusName(messageStatusMap, dataItem.status)}
                        </td>
                       <td class="align-center" width="200">
                           ${dataItem.create_time?datetime}
                       </td>
                   </tr>
               </#list>
           <#else>
               <tr>
                   <td class="align-center" colspan="5">
                       <span style="color:red;font-weight:bold;">您还没有相应的消息哦！</span>
                   </td>
               </tr>
           </#if>
           </tbody>
       </table>
       <@ctrl.pageShow (queryResult.total)!0, (queryResult.pageIndex)!0 />
   </form>
</@override>
<@override name="page-scripts">
    <script>
    var messageArray = [];
    $(function(){
        layui.use(['form','layer','jquery'], function(){
            var form=layui.form;
            var layer=layui.layer;
            var $ = layui.jquery;
            form.on('checkbox(fullCheck)', function (data) {
                messageArray.splice(0, messageArray.length);
                if(this.checked){
                    $('.messageItem').each(function(index, item){
                        item.checked = data.elem.checked;
                        var itemValue = $(this).val();
                        if($.inArray(itemValue, messageArray) == -1){
                            messageArray.push(itemValue);
                        }
                    });
                }else{
                    $('.messageItem').each(function(index, item){
                        item.checked = data.elem.checked;
                    });
                }
                form.render('checkbox');
            });
            form.on('checkbox(itemCheck)', function (data) {
                if(this.checked){
                    messageArray.push(data.value);
                }else{
                    messageArray.splice(messageArray.indexOf(data.value),1);
                }
            });
            $('.js-reset').on('click', function(){
                $('#pageNo').val(1);
                $('#status').val("");
                $('#type').val("");
                $('form:first').submit();
            });
            $(".js-delete").on('click', function(){
                messageBatch("您确定要删除选中的"+messageArray.length+"条消息吗？", "2");
            });
            $(".js-read").on('click', function(){
                messageBatch("您确定要标记选中的"+messageArray.length+"条消息为已读吗？","1");
            });
        })
    })
    function messageBatch(message, status){
        if(messageArray.length > 0){
           var params= {'logIds':messageArray.join(","),'status':status};
           confirmSubmit(message , params,"${contextPath}/message/receive/batch");
        }else{
            alert("请至少选择一项！");
        }
    }
    </script>
</@override>
<@extends name="/layout/basepage.html"/> 